package com.gogo.mall.controller;

import com.gogo.mall.entity.*;
import com.gogo.mall.result.ResponseCode;
import com.gogo.mall.result.ResponseData;
import com.gogo.mall.service.*;
import com.gogo.mall.service.impl.QyCateServiceImpl;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

@RestController
@RequestMapping("index")
public class QyIndex {

    @Autowired
    private QyBannerService qyBannerService;

    @Autowired
    private QyProductService qyProductService;

    @Autowired
    private QyIconService qyIconService;

    @Autowired
    private QyActiveService qyActiveService;

    @Autowired
    private QyFloorService qyFloorService;

    @Autowired
    private QyCateServiceImpl qyCateService;

    @GetMapping()
    public ResponseData Index(){
        Integer offset=0;
        Integer limit=999999;
        HashMap<String, Object> resMap = new HashMap<String, Object>();
        //获取轮播图
        List<QyBanner> banner = qyBannerService.queryAllByLimit(offset, limit);
        //获取活动信息
        List<QyActive> active = qyActiveService.queryAllByLimit(offset, limit);
        //获取图标
        List<QyIcon> icon = qyIconService.queryAllByLimit(offset, limit);
        //获取楼层
        List<QyFloor> floor = qyFloorService.queryAllByLimit(offset, limit);

        //获取首页推荐
        ArrayList<QyCate> resList = new ArrayList<>();
        //导航
        List<QyCate> list = qyCateService.queryAllByLimit(0, 4);
        for (QyCate cate : list) {
            QyCate cate1 = qyCateService.queryByRecommend(cate.getId());
            resList.add(cate1);
        }
        resMap.put("banner",banner);
        resMap.put("active",active);
        resMap.put("icon",icon);
        resMap.put("floor",floor);
        resMap.put("recommend_cate",list);
        resMap.put("cate",resList);
        return new ResponseData(ResponseCode.WEB_SUCCESS,resMap);
    }

    //根据id获取推荐分类数据
    @GetMapping("getRecInfo")
    public ResponseData getRecInfo (@Param("id") Integer id){
        return qyCateService.queryCategoryById(id);
    }

    /*
     * 热门搜索接口
     * 请求方式Get
     */


    @GetMapping("search")



}
